package cn.tedu.car.backend.checklist.controller;

import cn.tedu.car.backend.base.response.JsonResult;
import cn.tedu.car.backend.checklist.pojo.dto.CheckInsertParam;
import cn.tedu.car.backend.checklist.pojo.dto.CheckListParam;
import cn.tedu.car.backend.checklist.pojo.dto.PendingListParam;
import cn.tedu.car.backend.checklist.pojo.entity.CheckList;
import cn.tedu.car.backend.checklist.pojo.vo.CheckListVO;
import cn.tedu.car.backend.checklist.pojo.vo.PendingVO;
import cn.tedu.car.backend.checklist.service.CheckListService;
import cn.tedu.car.backend.checklist.service.PendingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/checklist/")
public class CompletedController {
    @Autowired
    private CheckListService checkListService;
    @Autowired
    private PendingService pendingService;
    @GetMapping("completed/select")
    public JsonResult selectList(CheckListParam checkListParam){
        log.debug("检查单查询参数{}",checkListParam);
        List<CheckListVO> list=checkListService.selectList(checkListParam);
        log.debug("检查单查询结果{}"+list.toString());
        return JsonResult.ok(list);
    }

    @PostMapping(value = "completed/del/{id}")
    public JsonResult deleteById(@PathVariable("id") Long id){
        log.debug("删除检查单入参:{}",id);
        checkListService.deleteByNum(id);
        return JsonResult.ok();
    }
    @PostMapping("completed/update")
    public JsonResult updateCheckList(CheckList checkList){
        log.debug("检查单修改入参:{}",checkList);
        checkListService.updateCheckList(checkList);
        return JsonResult.ok();
    }
    @PostMapping("completed/insert")
    public  JsonResult insertCheckList(CheckInsertParam checkList){
        log.debug("检查单添加入参:{}",checkList);
        checkListService.insertCheckList(checkList);
        return JsonResult.ok();
    }



    @GetMapping("pending/select")
    public JsonResult selectPendingList(PendingListParam pendingListParam){
        log.debug("待办单查询参数{}",pendingListParam);
        List<PendingVO> list=pendingService.selectList(pendingListParam);
        log.debug("待办单查询结果{}"+list.toString());
        return JsonResult.ok(list);
    }

    @PostMapping("pending/delete/{orderNo}")
    public JsonResult deletePending(@PathVariable String orderNo){
        pendingService.deleteByNum(orderNo);
        return JsonResult.ok();
    }


}
